class Account

  attr_accessor :balance
  def initialize(balance=0)
    @balance = balance
  end

  def to_s
    "Account has balance #{@balance}"
  end
end

class Transaction
  def initialize (account_a , account_b)
    @account_a = account_a
    @account_b = account_b
  end

  def debit(account , amount)
    account.balance -= amount
  end

  def credit(account , amount)
    account.balance += amount
  end

  def transfer(amount)
    self.debit(@account_a , amount)
    self.credit(@account_b , amount)
  end

end

a1 = Account.new(100);
a2 = Account.new(200)

puts 'Before transaction'

puts a1
puts a2

tr = Transaction.new(a1 , a2)
tr.transfer(20)

puts 'After transaction'

puts a1
puts a2